home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 843 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.7 KB

  1. Path: erich.triumf.ca!bennett
  2. From: bennett@erich.triumf.ca (P.Bennett)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: warning: possibly incorrect assignment
  5. Date: 9 Jan 1996 09:56 PST
  6. Organization: TRIUMF: Tri-University Meson Facility
  7. Distribution: world
  8. Message-ID: <9JAN199609561850@erich.triumf.ca>
  9. References: <Pine.OSF.3.91.960109091920.6447A-100000@io.UWinnipeg.ca>
  10. NNTP-Posting-Host: ftp.triumf.ca
  11. News-Software: VAX/VMS VNEWS 1.50    
  12.  
  13. In article <Pine.OSF.3.91.960109091920.6447A-100000@io.UWinnipeg.ca>, Bill Simpson <wsimpson@uwinnipeg.ca> writes...
  14. >I get the above warning when I compile code using the following
  15. >function.  It flags the **** line.
  16. ..
  17. >****        while(fp=fopen(file_name,"r"))
  18. ..
  19. >How can I write this code so the compiler does not issue this warning?
  20. >Please don't suggest I just tell the compiler to shut up.  In general
  21. >the warnings are useful.  I do not want to just ignore the warning either.
  22.  
  23. This is warning you of a possible common error - the compiler expects you to
  24. have a comparison (==) rather than an assignment (=) in the while(...).  Since
  25. typing "=" instead of "==" is a common error, the compiler issues the warning. 
  26. You can silence  the warning either by using an explicit comparison:
  27.     while((fp = fopen(...)) != NULL)
  28. or by enclosing the assignment in extra parenthesis:
  29.     while((fp = fopen(...)))
  30.  
  31.  
  32. Peter Bennett VE7CEI                | Vessels shall be deemed to be in sight
  33. Internet: bennett@triumf.ca         | of one another only when one can be
  34. Packet: ve7cei@ve7kit.#vanc.bc.ca   | observed visually from the other
  35. TRIUMF, Vancouver, B.C., Canada     |                          ColRegs 3(k)
  36. GPS and NMEA info and programs: ftp://sundae.triumf.ca/pub/peter/index.html
  37.  
  38.